//属性相关API

import request from '@/utils/request'
import type { CategoryResponseData, AttrResponseData, Attr } from './type'
//属性管理接口地址
enum API {
  //1级分类接口地址
  C1_URL = '/admin/product/getCategory1',
  //2级分类接口地址
  C2_URL = '/admin/product/getCategory2/',
  //3级分类接口地址
  C3_URL = '/admin/product/getCategory3/',
  //获取分类下已有的属性和属性值
  ATTR_URL = '/admin/product/attrInfoList/',
  //添加，修改已有的属性
  ADDORUPDAPTEATTR_URL = '/admin/product/saveAttrInfo',
  //删除已有属性接口
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

//获取1级分类的接口方法
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL)
//获取2级分类的接口方法
export const reqC2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C2_URL + category1Id)
//获取3级分类的接口方法
export const reqC3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C3_URL + category2Id)
//获取分类下已有的属性和属性接口
export const reqAttr = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
//新增，修改已有属性的接口方法
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDAPTEATTR_URL, data)
//删除已有属性的方法
export const reqRemoveAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId)
